package com.yugu.park.business.service.impl;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yugu.park.business.entity.CardInfo;
import com.yugu.park.business.entity.MemberInfo;
import com.yugu.park.business.mapper.MemberInfoMapper;
import com.yugu.park.business.service.CardInfoService;
import com.yugu.park.business.mapper.CardInfoMapper;
import com.yugu.park.enums.SequenceTypeEnum;
import com.yugu.park.system.service.TSysSequenceService;
import com.yugu.util.BeanCopyUtil;
import com.yugu.util.DataUtils;
import com.yugu.util.SearchPage;
import com.yugu.util.SysQueryParam;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
* @author Noble-Six
* @description 针对表【t_card_info】的数据库操作Service实现
* @createDate 2024-04-25 11:02:15
*/
@Service
public class CardInfoServiceImpl extends ServiceImpl<CardInfoMapper, CardInfo>
    implements CardInfoService{
    @Resource
    private CardInfoMapper cardInfoMapper;
    @Resource
    private MemberInfoMapper memberInfoMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addOrUpdate(CardInfo info) {
        CardInfo old = cardInfoMapper.selectById(info.getId());
        if (old != null) {
            BeanCopyUtil.copyProperties(info,old);
            cardInfoMapper.updateById(old);
        }else {
            info.setId(IdUtil.simpleUUID());
            cardInfoMapper.insert(info);
        }
    }

    @Override
    public PageInfo<CardInfo> page(SearchPage<SysQueryParam> search) {
        PageHelper.startPage(search.getPageNum(),search.getPageSize());
        List<CardInfo> list = cardInfoMapper.page(search.getSearch());
        return PageInfo.of(list);

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void removeIds(List<String> asList) {
        cardInfoMapper.removeIds(asList);
    }
}




